package cn.tedu.baking.controller;

import cn.tedu.baking.commons.response.JsonResult;
import cn.tedu.baking.pojo.dto.ContentDTO;
import cn.tedu.baking.pojo.vo.*;
import cn.tedu.baking.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/contents/")
public class ContentController {
    @Autowired
    IContentService service;
    @PostMapping("add-new")
    public JsonResult addNew(ContentDTO contentDTO){
        System.out.println("contentDTO = " + contentDTO);
        service.addNew(contentDTO);
        return JsonResult.ok();
    }
    @GetMapping("{type}/{userId}/management")
    public JsonResult managementList(@PathVariable Long type,
                                     @PathVariable Long userId){
        List<ContentManagementVO> list = service.listForManagement(type,userId);
        return JsonResult.ok(list);
    }
    @PostMapping("{id}/delete")
    public JsonResult delete(@PathVariable Long id){
        service.deleteById(id);
        return JsonResult.ok();
    }
    @GetMapping("{id}/update")
    public JsonResult selectForUpdateById(@PathVariable Long id){
        ContentUpdateVO contentUpdateVO = service.selectForUpdateById(id);
        return JsonResult.ok(contentUpdateVO);
    }
    @GetMapping("{type}/{categoryId}/index")
    public JsonResult listForIndexByTypeAndCategoryId(@PathVariable Long type,
                                                      @PathVariable Long categoryId){
        List<ContentIndexVO> list =
                service.listForIndexByTypeAndCategoryId(type,categoryId);
        return JsonResult.ok(list);
    }
    @GetMapping("{id}/detail")
    public JsonResult detailById(@PathVariable Long id){
        ContentDetailVO contentDetailVO = service.detailById(id);
        return JsonResult.ok(contentDetailVO);
    }
    @GetMapping("{id}/other")
    public JsonResult otherByUserId(@PathVariable Long id){
        List<ContentSimpleVO> list = service.otherByUserId(id);
        return JsonResult.ok(list);
    }
    @GetMapping("hot")
    public JsonResult hotList(){
        List<ContentSimpleVO> list = service.hotList();
        return JsonResult.ok(list);
    }
    @GetMapping("{type}/list")
    public JsonResult listByType(@PathVariable Long type){
        List<ContentIndexVO> list = service.listByType(type);
        System.out.println(list);
        return JsonResult.ok(list);
    }
    @GetMapping("{wd}/search")
    public JsonResult search(@PathVariable String wd){
        List<ContentIndexVO> list = service.searchByWd(wd);
        return JsonResult.ok(list);
    }
    @GetMapping("{type}/admin")
    public JsonResult listForAdmin(@PathVariable Long type){
        List<ContentAdminVO> list = service.listForAdmin(type);
        return JsonResult.ok(list);
    }

}
